use crate::ast::{RecordNode, RecordNodeType};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RecordType {
    Ipv4,
    Port,
    Number,
}

impl From<RecordNodeType> for RecordType {
    fn from(value: RecordNodeType) -> Self {
        match value {
            RecordNodeType::Ipv4 => RecordType::Ipv4,
            RecordNodeType::Port => RecordType::Port,
            RecordNodeType::Number => RecordType::Number,
        }
    }
}

#[derive(Debug, Clone)]
pub struct RecordTypeItem {
    pub label: String,
    pub r#type: RecordType,
}

#[derive(Debug, Clone)]
pub struct RecordItem {
    pub label: String,
    pub items: Vec<RecordTypeItem>,
}

impl<'input> From<&RecordNode<'input>> for RecordItem {
    fn from(value: &RecordNode<'input>) -> Self {
        RecordItem {
            label: value.label.to_string(),
            items: value
                .content
                .iter()
                .map(|item| RecordTypeItem {
                    label: item.label.to_string(),
                    r#type: item.r#type.into(),
                })
                .collect(),
        }
    }
}

pub trait RecordHandler {
    fn emit_item(&mut self, item: &RecordItem) -> u16;
}
